<template>
    <div class="bountiful-content">
        <h3>Experience All That We Offer to Supplement You</h3>
        <div class="products-grid">
            <div class="product-card best-sellers" @click="toAllProducts">
                <div class="best-sellers-content">
                    <h4>Best Sellers</h4>
                    <p>Our favorite solutions for your holistic health</p>
                    <button class="view-best-sellers">View Best Sellers</button>
                </div>
            </div>
            <div class="product-card" v-for="product in filterCarouselOfProduct" :key="product.id"
                @click="handleClickProduct(product)">
                <img :src="product.productImage[0]" alt="Probiotic 10" class="product-img">
                <p class="product-category">{{ product.name }}</p>
            </div>
        </div>
    </div>
</template>

<script>
import {
    selectProductList,
} from '@/config/api';
export default {
    name: "homeProducct",
    data() {
        return {
            productList: [],
            allProduct: [],
        };
    },
    computed: {
        filterCarouselOfProduct() {
            return JSON.parse(JSON.stringify(this.productList)).filter(item => item.productCarouselPic)
        }
    },
    created() {
        this.getProductList();
    },
    methods: {
        getProductList() {
            selectProductList().then((res) => {
                this.productList = res.data;
            });
        },
        handleClickProduct(product) {
            this.$router.push({
                path: '/products',
                query: {
                    productId: product.id
                }
            });
        },
        toAllProducts() {
            this.$router.push({
                path: "/allProduct",
            });
        },
    },
};
</script>

<style lang="less" scoped>
.bountiful-content {
    padding: 0 30px;
    padding-bottom: 130px;
    text-align: center;
    max-width: 1680px;
    margin: 0 auto;
}

.bountiful-content h3 {
    font-size: 40px;
    line-height: 50px;
    color: #27463a;
    text-align: center;
    margin-top: 48px;
    font-weight: 800;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .product-img {
        height: 450px !important;
    }

    .product-category {
        font-size: 2rem !important;
        line-height: 2 !important;
    }

    .best-sellers-content h4 {
        margin-bottom: 1rem;
        font-weight: 700;
        font-size: 40px;
        line-height: 50px;
        color: #d2e38f;
    }

    .best-sellers-content p {
        font-size: 2rem;
        margin-bottom: 2rem;
        line-height: 1.5;
    }

    .view-best-sellers {
        font-weight: 700;
        border: none;
        background-color: transparent;
        color: white;
        padding: 0.75rem 1.5rem;
        font-size: 1.8rem;
        cursor: pointer;
        transition: all 0.3s;
        align-self: center;
    }
}

@media (min-width: 1180px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .product-category {
        font-size: 1.5rem !important;
        line-height: 1.5 !important;
    }

    .best-sellers-content h4 {
        margin-bottom: 1rem;
        font-weight: 700;
        font-size: 35px;
        line-height: 50px;
        color: #d2e38f;
    }

    .best-sellers-content p {
        font-size: 1.7rem;
        margin-bottom: 2rem;
        line-height: 1.5;
    }

    .view-best-sellers {
        font-weight: 700;
        border: none;
        background-color: transparent;
        color: white;
        padding: 0.75rem 1.5rem;
        font-size: 1.5rem;
        cursor: pointer;
        transition: all 0.3s;
        align-self: center;
    }
}

@media (min-width: 1680px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .product-category {
        font-size: 1.2rem !important;
        line-height: 1.5 !important;
    }

    .best-sellers-content h4 {
        margin-bottom: 1rem;
        font-weight: 700;
        font-size: 28px;
        line-height: 50px;
        color: #d2e38f;
    }

    .best-sellers-content p {
        font-size: 1rem;
        margin-bottom: 2rem;
        line-height: 1.5;
    }

    .view-best-sellers {
        font-weight: 700;
        border: none;
        background-color: transparent;
        color: white;
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
        cursor: pointer;
        transition: all 0.3s;
        align-self: center;
    }
}

.products-grid {
    display: grid;
    column-gap: 36px;
    margin-top: 49px;
    row-gap: 50px;
    grid-template-rows: 1fr 1fr;
    width: 100%;
}

.view-best-sellers:hover {
    background-color: white;
    color: #2c5f2d;
}

.product-card {
    background-color: white;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0 auto;
    position: relative;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.product-card.best-sellers {
    background-color: #2c5f2d;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2rem;
}

.product-card:hover .product-img {
    transform: scale(1.05);
}

.product-card:hover .product-category {
    display: block;
}

.product-img {
    width: 100%;
    height: 350px;
    object-fit: cover;
    transition: transform 0.3s;
}

.product-category {
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-weight: bold;
    font-size: 1.2rem;
    line-height: 1.5;
    color: #1f1f1f;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 0.2rem;
    margin: 0;
    white-space: wrap;
}
</style>